import java.util.Arrays;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(myToString(array));
        int[] array2 = null;
        System.out.println(myToString(array2));
        System.out.println(find(array,2));
        reverse(array);
        System.out.println(myToString(array));


        int[] array3 = {1,2,3,4,5,12,256,436,9};
        int[] array4 = {1,2,3,4,5,12,256,436,9};
        boolean flag = Arrays.equals(array3,array4);//比较两个数组的值，一样为true，有一个不一样为false
        System.out.println(flag);


        int[] array5 = {1,2,3,4,5,12,256,436,9};
        Arrays.fill(array5,23);
        System.out.println(myToString(array5));
    }
    public static String myToString(int[] tmp){
        //手写toString
        //对tmp进行参数判断
        if (tmp == null){
            return "null";
        }
        String ret = "[";
        for (int i = 0; i < tmp.length; i++) {
            ret = ret +tmp[i];
            if (i != tmp.length-1){
                ret += ",";
            }
        }
        ret = ret + "]";
        return ret;
    }
    //二分查找——>建立在有序的情况下
    public static boolean find (int[] array,int i){
        int left = 0;
        int right = array.length-1 ;
        Arrays.sort(array);
        while (left <= right){
            int mid = left + (right - left)/2;
            if (array[mid] < i){
                left = mid + 1;
            } else if (array[mid] > i){
                right = mid - 1;
            }else {
                return true;
            }
        }
        return false;
    }
    //逆序输出  这里修改的是原array
    public static void reverse(int[] array){
        int left = 0;
        int right = array.length-1;
        while (left < right){
            int temp = array[left];
            array[left] = array[right];
            array[right] = temp;
            left++;
            right--;
        }
    }
}